package com.honey.mybatis.generator.dao.method;

import com.honey.compilation.java.AbstractJavaCompilation;
import com.honey.compilation.java.Parameter;
import com.honey.core.dbmapping.introspect.IntrospectSchema;
import com.honey.core.dbmapping.introspect.IntrospectSchemaColumn;
import com.honey.core.types.FullyQualifiedJavaType;
import com.honey.mybatis.generator.AbstractMethod;
import com.honey.mybatis.generator.MybatisPlugin;
import com.honey.mybatis.generator.dao.DaoConstant;
import com.honey.mybatis.generator.page.PageConstant;

public  abstract class AbstractCreateInterfaceMethod extends AbstractMethod  {
	
	private static final String[] ANNOTATION = new String[]{
		"@SuppressWarnings(\"unchecked\")"
	};
	
	public AbstractCreateInterfaceMethod(AbstractJavaCompilation clazz,
			MybatisPlugin belongPlugin, IntrospectSchema introspectSchema,
			IntrospectSchemaColumn introspectSchemaColumn) {
		super(clazz, belongPlugin, introspectSchema, introspectSchemaColumn);
		
	}
	/* (non-Javadoc)
	 * @see com.honey.mybatis.generator.AbstractMethod#getParameter()
	 */
	@Override
	protected Parameter[] getParameter() {
		Parameter[] answer = new Parameter[3];
		Parameter parameter = null;
		if( isUseSession()){
			parameter = new Parameter(DaoConstant.SQL_SESSION_PACKAGE,DaoConstant.SQL_SESSION_NAME);
			parameter.addJavaDocLine("外部传入SqlSession");
			answer[0] = parameter;
		}
		if( isCondition() ){
			parameter = new Parameter(getConditionClassType(introspectSchema.getSchema()),DaoConstant.CONDITION_VARIABLE_NAME);
			parameter.addJavaDocLine("动态查询语句");
			answer[1] = parameter;
		}
		
		if( isUsePage() && getUpdateEntityType () == null  ){
			parameter = new Parameter(new FullyQualifiedJavaType(mybatisPlugin.getModelTargetPackage()+"."+PageConstant.PAGE_NAME),PageConstant.PAGE_VARIABLE_NAME);
			parameter.addJavaDocLine("分页对象");
			answer[2] = parameter;
		}
		
		if( getUpdateEntityType () != null && !isUsePage() ){
			parameter = new Parameter(getUpdateEntityType(),/*ENTITY_VARIABLE_NAME*/ super.getEntityVariableName(introspectSchema.getSchema()));
			parameter.addJavaDocLine("需要操作的实体");
			answer[2] = parameter;
		}
		return answer;
	}

	/* (non-Javadoc)
	 * @see com.honey.mybatis.generator.AbstractMethod#getAnnotation()
	 */
	@Override
	protected String[] getAnnotation() {
		return ANNOTATION;
	}

	/**
	 * @return the isCondition
	 */
	public boolean isCondition() {
		return true;
	}


	/**
	 * @return the useSqlSession
	 */
	public boolean isUseSession() {
		return false;
	}


	/**
	 * @return the usePage
	 */
	public boolean isUsePage() {
		return false;
	}
	
	
	public FullyQualifiedJavaType getUpdateEntityType(){
		return null;
	}
	
}
